﻿// JAW Edit Version 1.10
// August 19 2007
// Alan To 
// modified by Toby Lawrence (Apr 16 2008)

using System;
using System.Collections.Generic;
using System.Text;

namespace JAW
{
	/// <summary>
	/// Contains JAW-specific constants.
	/// </summary>
	public static class Constants
	{
		public const int JAWFirmwareSize = 7186;
		public const int JAWDataChunkSize = 64;
		public const int JAWFirmwareChunkCount = JAWFirmwareSize / JAWDataChunkSize;
		public const int JAWVoutUpdateSize = 1024;
		public const int JAWVoutUpdateChunkCount = JAWVoutUpdateSize / JAWDataChunkSize;
		public const string JAWSettingsFileHeader = "JAWEDIT";
		public const string JAWDataloggingDelimiter = ",";
		public const string JAWDatalogFilename = "datalog";
		public const string JAWDatalogFileExtension = "CSV";
		public const string JAWSettingsFilename = "JAWSettings";
		public const string JAWSettingsFileExtension = "xml";
	}

	/// <summary>
	/// Commands sent by the software to the JAW device.
	/// </summary>
	public enum JAWCommand : byte
	{
		/// <summary>
		/// Gets the synchronization byte (<see cref="JAWReturnCode.Synchronized" />), device ID,
		/// HW version, and bootloader version.
		/// </summary>
		/// <remarks>Decimal value of 0.  Must be in the bootloader.</remarks>
		GetDeviceInfo = 0x00,
		/// <summary>
		/// Tells the device to start sending datalogging info.
		/// </summary>
		/// <remarks>Decimal value of 0.  Must be used when the bootloader is not running.</remarks>
		SendDataloggingInfo = 0x00,
		/// <summary>
		/// Tells the bootloader to expect a Vout table update being sent.
		/// </summary>
		/// <remarks>Decimal value of 1.  Must be in the bootloader.</remarks>
		IncomingVoutUpdate = 0x01,
		/// <summary>
		/// Tells the bootloader to expect a firmware update being sent.
		/// </summary>
		/// <remarks>Decimal value of 2.  Must be in the bootloader.</remarks>
		IncomingFirmwareUpdate = 0x02,
		/// <summary>
		/// Gets the calibration value for the device.
		/// </summary>
		/// <remarks>Decimal value of 2.  Must be used when the bootloader is not running.</remarks>
		GetCalibrationValue = 0x02,
		/// <summary>
		/// Sets the calibration value for the device.
		/// </summary>
		/// <remarks>Decimal value of 3.</remarks>
		SetCalibrationValue = 0x03,
		/// <summary>
		/// Tells the device to perform a free-air calibration.
		/// </summary>
		/// <remarks>Decimal value of 4.</remarks>
		PerformFreeAirCalibration = 0x04,
		/// <summary>
		/// Gets the firmware ID of the device.
		/// </summary>
		/// <remarks>Decimal value of 5.</remarks>
		GetFirmwareID = 0x05,
		/// <summary>
		/// Sets the refresh rate of the device.
		/// </summary>
		/// <remarks>Decimal value of 6.</remarks>
		SetRefreshRate = 0x06,
		/// <summary>
		/// Sets the external display output of the device. (AFR or Lambda)
		/// </summary>
		/// <remarks>Decimal value of 7.</remarks>
		SetExternalDisplay = 0x07,
		/// <summary>
		/// Sets the ignition per revolution rate of the device.
		/// </summary>
		/// <remarks>Decimal value of 8.</remarks>
		SetIPR = 0x08,
		/// <summary>
		/// Tells JAW to load the bootloader.
		/// </summary>
		/// <remarks>Decimal value of 170.</remarks>
		LoadBootloader = 0xAA,
		/// <summary>
		/// Tells JAW to exit the bootloader.
		/// </summary>
		/// <remarks>Decimal value is 255.</remarks>
		ExitBootloader = 0xFF
	}

	/// <summary>
	/// Values sent by the JAW device after executing certain commands.
	/// </summary>
	public enum JAWReturnCode : byte
	{
		/// <summary>
		/// Default value for a bad return code.
		/// </summary>
		/// <remarks>Decimal value is 0.</remarks>
		None = 0x00,
		/// <summary>
		/// Device is synchronized and ready to recieve a firmware update.
		/// </summary>
		/// <remarks>Decimal value is 128.</remarks>
		Synchronized = 0x80,
		/// <summary>
		/// Data has been received and written; more data can be sent to the device now.
		/// </summary>
		/// <remarks>Decimal value is 255.</remarks>
		BlockWriteFinished = 0xFF
	}

	/// <summary>
	/// Error codes thrown during device updating.
	/// </summary>
	public enum DeviceUpdateError : byte
	{
		/// <summary>
		/// No error encountered.
		/// </summary>
		None = 0x00,
		/// <summary>
		/// An error occured during writing to the device; the data the device received did not match what was sent.
		/// </summary>
		WriteError = 0x01,
		/// <summary>
		/// The device is not synchronized; data cannot be sent.
		/// </summary>
		DeviceNotSynchronized = 0x02,
	}
}
